#ifndef LIBRARY_H
#define LIBRARY_H

#include <QObject>
#include <QVector>
#include <QMutex>
#include "utils.h"

typedef QSharedPointer<QMutex> book_t;

struct ReadOnlyLibrary
{
    virtual size_t getBookCount() = 0;
    virtual book_t getBook(size_t index) = 0;
    virtual void returnBook(book_t) = 0;

    virtual size_t readInterval() = 0;

    virtual ~ReadOnlyLibrary(){}
};

class Library : public QObject, public ReadOnlyLibrary
{
private:
    Q_OBJECT
    QVector<book_t> _books;
    QMutex _library;

    volatile size_t _readInterval;
    volatile size_t _writeInterval;
    volatile size_t _maxBooksCount;

    size_t _waitCount;

public:
    Library();

    virtual size_t getBookCount();
    virtual book_t getBook(size_t index);
    virtual void returnBook(book_t book);

    int addBook();

    virtual size_t readInterval();
    size_t writeInterval();

    bool isFull();

signals:
    void booksCountChanged(int booksCount);
    void waitCountChanged(int waitCount);

public slots:
    void setBooksMaxCount(int maxCount);
    void setReadInterval(int interval);
    void setWriteInterval(int interval);
};

#endif // LIBRARY_H
